# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>
# Contributor: TheEdgeOfRage on AUR

_pkgname=aws-crt-python
pkgname=python-awscrt
# https://github.com/awslabs/aws-crt-python/releases
# UPDATE_BLOCKED: newer python-awscrt often needs newer aws-c-* libraries - update only when dependencies are updated
pkgver=0.16.15
pkgrel=2
pkgdesc='A common runtime for AWS Python projects'
arch=(loong64 x86_64)
url='https://github.com/awslabs/aws-crt-python'
license=(Apache)
depends=(glibc python
         aws-c-auth aws-c-cal aws-c-common aws-c-event-stream aws-c-http aws-c-io aws-c-mqtt aws-c-s3 aws-checksums)
makedepends=(cmake python-build python-installer python-setuptools python-wheel)
checkdepends=(python-websockets)
source=("https://github.com/awslabs/aws-crt-python/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('5bcdcd57f30245b4443a59c89e7b64227246f2123d1c6f9315e95f24e0289fc7')

prepare() {
  cd $_pkgname-$pkgver
  # Allow linking to shared libraries
  sed -i '/:lib/d' setup.py
  # Use proper version in .dist-info
  # See https://github.com/awslabs/aws-crt-python/blob/main/continuous-delivery/update-version.py
  sed -i -r "s/__version__ = '[^']+'/__version__ = '$pkgver'/" awscrt/__init__.py
}

build() {
  cd $_pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_pkgname-$pkgver

  pyver=$(python -c "import sys; print('{}{}'.format(*sys.version_info[:2]))")
  export PYTHONPATH="$PWD:$PWD/build/lib.linux-$CARCH-cpython-$pyver"
  python -m unittest discover test
}

package() {
  cd $_pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
}
